package ltu.m7011e.client.presenter;

import ltu.m7011e.client.event.GoToMainViewEvent;
import ltu.m7011e.client.event.PostLinkEvent;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

public class UserInfoPresenter implements Presenter {  

	public interface Display {
		HasClickHandlers getHomeButton();
		Widget asWidget();
	}
	
	private final HandlerManager eventBus;
	private final Display display;
	
	public UserInfoPresenter(HandlerManager eventBus, Display view) {
		this.eventBus = eventBus;
		this.display = view;
	}
	
	public void bind() {
		display.getHomeButton().addClickHandler(new ClickHandler() {   
			public void onClick(ClickEvent event) {
				GWT.log("[ClickEvent] Fire - GoToMainView !");
				eventBus.fireEvent(new GoToMainViewEvent());
			}
		}); 
	}
	
	public void go(final HasWidgets container) {
		bind();
		container.clear();
		container.add(display.asWidget());
	}


}
